package no_git_group.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.junit.Assert.assertEquals;
import static org.openqa.selenium.support.ui.ExpectedConditions.*;

public class HomePage extends AnyPage {

	public HomePage(PageManager pages) {
		super(pages);
	}

  @FindBy(css = "img[alt=\"Add movie\"]")
  private WebElement addMovieButton;
  
  @FindBy(id = "q")
  private WebElement searchButton;
  
  @FindBy(className = "content")
  private WebElement errorText;
  
  //assertEquals("No movies where found.",driver.findElement(By.className("content")).getText());

  public void clickAddMovie() {
    addMovieButton.click();
  }
  
  public HomePage searchMovie(String title1) {
	    searchButton.clear();
	    searchButton.sendKeys(title1 + Keys.RETURN);
	    return this;
	  }
  
  public HomePage verifySearch(String title1) {
	  driver.findElement(By.cssSelector("div[title=\"Amelie\"]"));
	  
	  return this;
  }
  
  public boolean isErrorFound() {
	  boolean result = false;
	  if (errorText.getText() == "No movies where found.")
		  result = false;
	  else
		  result = true;
	  return result;
  }
  
  public void openMovie(String title) {
	  //driver.findElement(By.cssSelector("div[title=\"Amelie\"]")).click();
	  driver.findElement(By.cssSelector("div.nocover")).click();
  }

  
}
